﻿@{
    ViewBag.Title = "Knowledge Library";
}

<div class="container bs-docs-container" id="emberApp"></div>

@section Styles {
    <style type="text/css">
        .loading {
            position: fixed;
            top: 50%;
            left: 50%;
        }

        a.before:before {
            content: attr(data-before)
        }
        .hover .hover-show {
            display: none;
        }
        .hover:hover .hover-show {
            display: block;
        }

        .navbar-margintop {
            margin-top: 30px;
        }

        .span3 {
            max-height: 56px;
            line-height: 18px;
            word-wrap: break-word;
            word-break: break-all;

            text-overflow: ellipsis;
        }

        .bs-docs-section .affix-top {
            margin-top: 30px;
        }
        .bs-docs-section .affix {
            position: fixed;

            top: 50px;

            z-index: 1000;
            background-color: #ffffff;
            padding-top: 30px;
            padding-bottom: 1px;
            border-bottom: 2px solid #999;
        }
        @@media screen and (max-width: 991px) {
            .bs-docs-section .affix {
                right: 15px;
                left: 15px;
            }
        }
        @@media screen and (min-width: 992px){
            .bs-docs-section .affix {
                width: 698px;            
            }
        }
        @@media screen and (min-width: 1200px){
            .bs-docs-section .affix {
                width: 848px;
            }
        }
        .bs-docs-section .affix + .page-header {
            margin-top: 105px;
        }

        .media {
            border-bottom: 1px solid #eee;
            margin-top: 0px;
            padding-bottom: 15px;
        }
        .media:hover {
            background-color: #eee;
            border-bottom: 1px solid #0094ff;
        }

        #d2tcontainer .pull-left {
            margin-right: 10px;
            background-color: #ffd8cc;
            border: 1px solid #ffd800;
        }

        .close {
            padding-left: 5px;
        }
    </style>
    @Stylesheet.Render("lhgdialog")
    @Stylesheet.Render("prettify")
}

@section Scripts {
    @Javascript.Render("json")
    @Javascript.Render("ember")
    @Javascript.Render("lhgdialog")
    @Javascript.Render("prettify")

    <script type="text/javascript">
        Ember.$.model = {
            add: function (url, emberModel, callback) {
                var postData = emberModel.toJSON ? emberModel.toJSON() : emberModel;
                $.ajax({
                    url: '/Model/' + url,
                    type: 'POST',
                    data: postData,
                    async: false
                }).then(function (result) {
                    if (result.Success) {
                        callback(result.Data);
                    }
                });
            },
            mod: function (url, emberModel, callback) {
                var putData = emberModel.toJSON ? emberModel.toJSON() : emberModel;
                putData.id = emberModel.id;
                $.ajax({
                    url: '/Model/' + url,
                    type: 'PUT',
                    data: putData,
                    async: false
                }).then(function (result) {
                    if (result.Success) {
                        callback(result.Data);
                    }
                });
            },
            del: function (url, emberModel, callback) {
                $.ajax({
                    url: '/Model/' + url,
                    type: 'DELETE',
                    async: false,
                    data: {
                        id: emberModel.id
                    }
                }).then(function (result) {
                    if (result.Success) {
                        callback(result.Data);
                    }
                });
            }
        };

        Ember.$.loadView = function (name) {
            var html;
            $.ajax({
                url: '/Content/knowledge.assets/hbs/' + name + '.hbs',
                type: 'GET',
                async: false
            }).then(function (htm) {
                html = htm;
            });
            return Ember.Handlebars.compile(html);
        }

        var _type = {};
        function Type() {
            if (_type.Name != location.pathname.split('/')[2]) {
                _type.Name = location.pathname.split('/')[2];
                $.ajax({
                    url: '/Model/KnowledgeType/GetIDByName?typeName=' + _type.Name,
                    type: 'GET',
                    async: false
                }).then(function (result) {
                    if (result.Success) {
                        _type.id = result.Data;
                    }
                })
            }
            return _type;
        }

        $(function () {
            if (userJson.UserName == 'ligd' ||
                userJson.UserName == 'chenhy03' ||
                userJson.UserName == 'jinjw' ||
                userJson.UserName == 'liuy03') {
                $('.hover-show').find('.hidden')
                    .removeClass('hidden');
            };
        });
    </script>

    <!-- App -->
    <script type="text/javascript" src="/Content/knowledge.assets/js/Application.js"></script>
    <!-- Model -->
    <script type="text/javascript" src="/Models/Knowledge-KnowledgeDetailType"></script>
    <script type="text/javascript" src="/Models/Knowledge-KnowledgeDetail"></script>
    <!-- Controller -->
    <script type="text/javascript" src="/Content/knowledge.assets/js/Controller.KnowledgeDetailType.js"></script>
    <script type="text/javascript" src="/Content/knowledge.assets/js/Controller.KnowledgeDetail.js"></script>
    <!-- Router -->
    <script type="text/javascript" src="/Content/knowledge.assets/js/Router.js"></script>
    <script type="text/javascript" src="/Content/knowledge.assets/js/Router.KnowledgeDetailType.js"></script>
    <script type="text/javascript" src="/Content/knowledge.assets/js/Router.KnowledgeDetail.js"></script>
    <!-- View -->
    <script type="text/javascript" src="/Content/knowledge.assets/js/View.KnowledgeDetailType.js"></script>
    <script type="text/javascript" src="/Content/knowledge.assets/js/View.KnowledgeDetail.js"></script>
    <!-- HBS -->
    <script type="text/x-handlebars">
        <div class="row">
            <!-- Nav -->
            <div class="col-md-3">
                <div class="bs-sidebar hidden-print" role="complementary">
                    <ul class="nav bs-sidenav">
                    {{#each kt in knowledgeDetailTypes itemController="knowledgeDetailType"}}
                        {{#link-to "knowledgedetail" kt.id tagName="li" class="hover" bubbles=false}}
                            <a {{bind-attr data-before="before"}} class="before">{{kt.Name}}
                                <div class="hover-show pull-right">
                                    <i class="icon-edit" {{action "edit" bubbles=false}}></i>
                                    <i class="icon-remove-sign hidden" {{action "del" bubbles=false}}></i>
                                </div>
                            </a>
                        {{/link-to}}
                    {{/each}}
                        <li>
                            {{#link-to "knowledgedetailtype.createtype"}}
                                #新增知识库分类
                            {{/link-to}}
                        </li>
                    </ul>
                </div>
            </div>
            <!-- ./Nav -->

            <!-- Main -->
            <div class="col-md-9" role="main">
                <div class="bs-docs-section">
                {{outlet}}
                </div>
            </div>
            <!-- ./Main -->
        </div>

        <div id="selectDetailType" class="hidden">
	        {{view Ember.Select class="form-control"
		        contentBinding="knowledgeDetailTypes"
		        optionValuePath="content.id"
		        optionLabelPath="content.Name"}}
        </div>
    </script>

    <script type="text/x-handlebars" data-template-name="loading">
      <div class="loading">Loading...</div>
    </script>

    <script type="text/x-handlebars" data-template-name="knowledgeDetailType/edit">
        {{view KnowledgeDetailTypeEdit}}
    </script>

    <script type="text/x-handlebars" data-template-name="knowledgeDetail/list">
        {{view KnowledgeDetailList}}
    </script>
    <script type="text/x-handlebars" data-template-name="knowledgeDetail/edit">
        {{view KnowledgeDetailEdit}}
    </script>
    <script type="text/x-handlebars" data-template-name="knowledgeDetail/detail">
        {{view KnowledgeDetailDetial}}
    </script>

    <script type="text/javascript" src="/Content/knowledge.assets/ckeditor/ckeditor.js"></script>
}